<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="下单时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.orderTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.orderNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收件人" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.recipientName }}</p>
            <p>手机号: {{ scope.row.recipient }}</p>
            <p>地区: {{ scope.row.recipientArea }}</p>
            <p>详细住址: {{ scope.row.recipientAddress }}</p>

            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.recipientName }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.orderStatus }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单金额/元" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.paymentAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit1(scope.$index, scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="success"
            v-if="scope.row.orderStatus == '送达'"
            @click="handleEdit2(scope.$index, scope.row)"
            >签收</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        :page-size="6"
        layout="prev, pager, next"
        @current-change="currentchange"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { ViewOrder } from "@/request/api";
import { StateAPI } from "@/request/api";
export default {
  data() {
    return {
      tableData: [
        {
          orderTime: "",
          recipientName: "",
          orderStatus: "",
          paymentAmount: "",
          logisticscompany: "",
          orderNumber: "",
          recipientAddress: "",
          recipientArea: "",
          recipient: "",
        },
      ],
      pageNumber: 1,
      total: 0,
    };
  },
  methods: {
    handleEdit1(index, row) {
      console.log(index, row);
      this.$router.push({
        path: "/logisticsMap",
        query: {
          numberValidateForm: row,
          routers: "/viewlogistics",
        },
      });
    },
    handleEdit2(index, row) {
      console.log(index, row);
      this.tableData[index].orderStatus = "已签收";
      StateAPI(this.tableData[index]).then((res) => {
        console.log(res);
        this.$message({
          type: "success",
          message: "物件已签收",
        });
      });
    },
    currentchange(value) {
      ViewOrder({
        params: {
          pageNumber: value,
        },
      }).then((res) => {
        this.tableData = res.data.data.rows;
        this.total = res.data.data.total;
      });
    },
  },

  created() {
    ViewOrder({
      params: {
        pageNumber: this.pageNumber,
      },
    }).then((res) => {
      this.tableData = res.data.data.rows;
      this.total = res.data.data.total;
    });
  },
};
</script>